import {
	autoLogin
} from '@/common/tools/util.js'
import store from '@/store/index';
import { login } from '../../api/user.js'

export default function authLogin(login_type) {
	return new Promise((resolve, reject) => {
		autoLogin().then(userInfo => {
			if (login_type !== undefined) userInfo.login_type = 'routine';
			login(userInfo).then(res => {
				store.commit('user/SET_TOKEN', res.result.token);
				store.commit('user/SET_USER', res.result.userInfo);
				resolve();
			}).catch(err => {
				reject();
			});
		}).catch(err => {
			reject();
		});
	})
}
